package com.beibei.framework.aspect;

import javax.servlet.http.HttpServletRequest;
import javax.xml.ws.WebServiceContext;
import javax.xml.ws.handler.MessageContext;

import org.apache.cxf.transport.http.AbstractHTTPDestination;

import com.beibei.framework.logger.ILogger;
import com.beibei.framework.logger.LoggerFactory;

/**
 * Spring AOP定义
 * 
 * @author 309814490@qq.com
 * @since 2014-02-14
 */
public class BaseAspect {

	protected ILogger getCommonLog() {
		return LoggerFactory.getCommonLog(this.getClass());
	}

	/**
	 * 获取调用方的IP
	 * 
	 * @param context
	 * @return
	 */
	protected String getUserIp(WebServiceContext context) {
		try {
			MessageContext ctx = context.getMessageContext();
			if (ctx != null) {
				HttpServletRequest request = (HttpServletRequest) ctx
						.get(AbstractHTTPDestination.HTTP_REQUEST);
				return request.getRemoteAddr();
			}
		} catch (Exception e) {
			getCommonLog().error("getUserIp", "error", e);
		}

		return "127.0.0.1";
	}

}
